package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
)

// OrderItem schema.
type OrderItem struct {
	ent.Schema
}

// Mixin of the OrderItem.
func (OrderItem) Mixin() []ent.Mixin {
	return []ent.Mixin{
		ormMixin{},
	}
}

// Annotations of the OrderItem.
func (OrderItem) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{Table: "order_item"},
	}
}

// Fields of the OrderItem.
func (OrderItem) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("order_id").Optional(),
		field.Int64("item_id").Immutable(),
		field.String("item_name").Immutable(),
		field.Int32("number").Immutable(),
		field.Int32("price"),
	}
}

// Edges of the OrderItem.
func (OrderItem) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("order", Order.Type).Ref("items").Unique().Field("order_id"),
	}
}
